﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PureMVC.Patterns;
using PureMVC.Interfaces;
using PureMVC.utils;
using PureMVC.MVC.Contollers.App;
using System.Windows.Forms;

namespace PureMVC.MVC
{
    class AppMainFacade : Facade
    {
        /// <summary>
        /// 单例实例
        /// </summary>
        public new static IFacade Instance
        {
            get
            {
                if (m_instance == null)
                {
                    lock (m_staticSyncRoot)
                    {
                        if (m_instance == null) m_instance = new AppMainFacade();
                    }
                }

                return m_instance;
            }
        }

        /// <summary>
        /// MVCApp启动入口
        /// </summary>
        public void startup()
        {
            UtilsLogger.init();
            UtilsLogger.trace("start up");
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            MainWindow window = new MainWindow();
            SendNotification(Notifications.APP_START_UP, window);
            SendNotification(Notifications.APP_MVC_REGISTER);
            Application.Run(window);
        }

        protected override void InitializeController()
        {
            base.InitializeController();
            RegisterCommand(Notifications.APP_START_UP,typeof(CommandStartUp));
            RegisterCommand(Notifications.APP_START_OVER, typeof(CommandStartOver));
            RegisterCommand(Notifications.APP_MVC_REGISTER, typeof(CommandRegisterMVC));
        }
    }
}
